<template>
  <div class="box">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="- 没有更多电影了 -"
      @load="onLoad"
    >
      <van-card v-for="item in list" :key="item.filmId">
        <template #title>
          <div class="title">
            {{ item.name }}<span>{{ item.item.name }}</span>
          </div>
        </template>
        <template #desc>
          <div class="label">
            观众评分:<span>{{ item.grade }}</span>
          </div>
          <div class="label actors">主演:{{ item.actors | handlerActors }}</div>
          <div class="label">{{ item.nation }} | {{ item.runtime }}分钟</div>
        </template>
        <template #thumb>
          <img width="66px" height="92.52px" :src="item.poster" alt="" />
        </template>
        <template #tags>
          <van-tag
            plain
            type="danger"
            class="button"
            size="large"
            color="#ff5f16"
            >购票</van-tag
          >
        </template>
      </van-card>
    </van-list>
  </div>
</template>
<script>
//导入配置好的请求地址
import api from '@/api'
import Vue from 'vue'
import { Card, Tag, List } from 'vant'

Vue.use(Card)
Vue.use(Tag)
Vue.use(List)
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      pageNum: 1
    }
  },
  filters: {
    handlerActors(val) {
      if (val) {
        let arr = val.map((item) => item.name)
        return arr.join(' ')
      } else {
        return '暂无主演'
      }
    }
  },
  methods: {
    onLoad() {
      this.$http.get(api.getNow + '?pageNum=' + this.pageNum).then((res) => {
        // this.loading = false
        if (res.status === 0 && res.msg === 'ok') {
          if (this.list.length < res.data.total) {
            this.list.push(...res.data.films)
            this.pageNum++
          } else {
            this.finished = true
          }
          this.loading = false
        }
      })
    }
  },
  created() {
    // console.log(api)
  }
}
</script>
<style lang='scss' scoped>
.box {
  padding-bottom: 50px;
  .title {
    color: #191a1b;
    font-size: 16px;
    height: 22px;
    line-height: 22px;
    span {
      font-size: 9px;
      background-color: #d2d6dc;
      color: #fff;
      height: 14px;
      line-height: 14px;
      padding: 0 2px;
      border-radius: 2px;
      margin-left: 5px;
      position: relative;
      top: -2px;
    }
  }
  .label {
    font-size: 13px;
    margin-top: 4px;
    color: #797d82;
    span {
      color: #ffb232;
      font-size: 14px;
    }
  }
  .actors {
    width: 174px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .button {
    position: absolute;
    right: 0;
    bottom: 40px;
  }
  .van-card__thumb {
    width: 77px;
  }
}
</style>
